from pymongo import MongoClient

connect = MongoClient("mongodb://root:123@127.0.0.1:27017/admin")

my_db = connect["mofang"]

my_collection = my_db["my_collections"]

# query = {"name":"xiaobai"}
# ret = my_collection.delete_one(query)
# print(ret.deleted_count)

# data = {"name":"xiaoming1号","age":20,"sex":True}
# ret = my_collection.insert_one(data)
# print(ret.inserted_id)

# query = {"name":"xiaoming1号"}
# ret = my_collection.delete_many(query)
# print(ret.deleted_count)

# query = {"name":"xiaohei"}
# document = my_collection.find_one_and_delete(query)
# print(document)

# query = {"name":"xiaofei"}
# upset = {"$set":{"age":24}}
# ret = my_collection.update_one(query,upset)
# print(ret.modified_count)

# query = {"name":"xiaofei"}
# upset = {"$inc":{"age":-1}}
# ret = my_collection.update_one(query,upset)
# print(ret.modified_count)

query = {"mobile":{"$regex":"^133"}}
upset = {"$set":{"mobile":"18500419869"}}
ret = my_collection.update_many(query,upset)
print(ret.modified_count)


